{
  "nbformat": 4,
  "nbformat_minor": 0,
  "metadata": {
    "kernelspec": {
      "name": "python3",
      "display_name": "Python 3"
    },
    "colab": {
      "name": "Getting_Started.ipynb",
      "version": "0.3.2",
      "provenance": [],
      "collapsed_sections": []
    }
  },
  "cells": [
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "pVDdXl-AzLsW",
        "colab_type": "text"
      },
      "source": [
        "# Getting Started\n",
        "\n",
        "In this tutorial, you will know how to\n",
        "- use the models in **tatk** to build a dialog agent.\n",
        "- build a simulator to chat with the agent and evaluate the performance.\n",
        "- try different module combinations.\n",
        "\n",
        "Let's get started!"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "sUhkMPYWE3XO",
        "colab_type": "text"
      },
      "source": [
        "## Environment Setup\n",
        "Run the command below to install tatk for once. Then restart the notebook and ignore this commend."
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "m5YgCJuLzkOv",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "# first install tatk and restart the notebook\n",
        "! rm -rf tatk && git clone https://github.com/thu-coai/tatk.git && cd tatk && pip install -e ."
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "Ec2qTTc4zLsY",
        "colab_type": "text"
      },
      "source": [
        "## Build an agent\n",
        "\n",
        "We use the models adapted on [Multiwoz dataset](https://www.aclweb.org/anthology/D18-1547) to build our agent. This pipeline agent consists of NLU, DST, Policy and NLG modules.\n",
        "\n",
        "First, import some models:"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "z1EUye0VzLsZ",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "import sys\n",
        "import os\n",
        "# Agent\n",
        "from tatk.dialog_agent import PipelineAgent, BiSession\n",
        "# common import: tatk.$module.$model.$dataset\n",
        "from tatk.nlu.svm.multiwoz import SVMNLU\n",
        "from tatk.nlu.bert.multiwoz import BERTNLU\n",
        "from tatk.dst.rule.multiwoz import RuleDST\n",
        "from tatk.policy.rule.multiwoz import Rule\n",
        "from tatk.nlg.template.multiwoz import TemplateNLG\n",
        "from tatk.evaluator.multiwoz_eval import MultiWozEvaluator\n",
        "import random\n",
        "import numpy as np\n",
        "from pprint import pprint"
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "4blugP4xzLsc",
        "colab_type": "text"
      },
      "source": [
        "Then, create the models and build an agent:"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "0cwV57AVzLsc",
        "colab_type": "code",
        "outputId": "6cff09a9-7884-4fb1-9a8b-f9f67126987c",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 85
        }
      },
      "source": [
        "# svm nlu trained on usr sentence of multiwoz\n",
        "# go to README.md under `tatk/tatk/nlu/svm/multiwoz` for more information \n",
        "sys_nlu = SVMNLU(mode='usr')\n",
        "# simple rule DST\n",
        "sys_dst = RuleDST()\n",
        "# rule policy\n",
        "sys_policy = Rule(character='sys')\n",
        "# template NLG\n",
        "sys_nlg = TemplateNLG(is_user=False)\n",
        "# assemble\n",
        "sys_agent = PipelineAgent(sys_nlu, sys_dst, sys_policy, sys_nlg)\n"
      ],
      "execution_count": 2,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "[<tatk.nlu.svm.Features.nbest object at 0x7f076a468e80>]\n",
            "Load from model_file param\n",
            "loading saved Classifier\n",
            "loaded.\n"
          ],
          "name": "stdout"
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "cVJZ63CwzLsg",
        "colab_type": "text"
      },
      "source": [
        "That's all! Let's chat with the agent using its `response` function:"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "Et-Rc6jOzLsg",
        "colab_type": "code",
        "outputId": "a6ea94c5-0664-437f-90a3-9644b15841f0",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 34
        }
      },
      "source": [
        "sys_agent.response(\"I want to find a moderate hotel\")"
      ],
      "execution_count": 3,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "'I have 18 options for you. Will acorn guest house be alright ? The parking is free . How about acorn guest house ?'"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 3
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "xpKzSlWvzLsj",
        "colab_type": "code",
        "outputId": "47a241a0-b38d-48cf-e0bf-30dddfe4c95f",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 34
        }
      },
      "source": [
        "sys_agent.response(\"Which type of hotel is it ?\")"
      ],
      "execution_count": 4,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "'It is a guesthouse .'"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 4
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "byx2hhf_zLsl",
        "colab_type": "code",
        "outputId": "338d2aa2-39e2-458f-b1ff-1648b1d31da5",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 34
        }
      },
      "source": [
        "sys_agent.response(\"OK , where is its address ?\")"
      ],
      "execution_count": 5,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "'Their address in our system is listed as pool way, whitehill road, off newmarket road .'"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 5
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "C7scb4RHzLsm",
        "colab_type": "code",
        "outputId": "8691bb1a-db5a-41a1-8bb9-774a8cab3faf",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 34
        }
      },
      "source": [
        "sys_agent.response(\"Thank you !\")"
      ],
      "execution_count": 6,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "'Welcome , it was a pleasure serving you .'"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 6
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "WmWF55UrzLso",
        "colab_type": "code",
        "outputId": "c730fb33-6b9c-4b38-88b8-b936ca533487",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 34
        }
      },
      "source": [
        "sys_agent.response(\"Try to find me a Chinese restaurant in south area .\")"
      ],
      "execution_count": 7,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "'There are 3 restaurants in that area that fit that criteria . Excellent . the lucky star is just your thing . Okay , may i suggest chinese food ?'"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 7
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "R-cseCinzLsq",
        "colab_type": "code",
        "outputId": "f530e567-289f-407a-afeb-6b8bb2523ba1",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 34
        }
      },
      "source": [
        "sys_agent.response(\"Which kind of food it provides ?\")"
      ],
      "execution_count": 8,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "'That is a chinese restaurant .'"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 8
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "kMLTBFL6zLst",
        "colab_type": "code",
        "outputId": "a8de4fde-bd1b-4a8d-bdeb-4e3b55efd983",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 34
        }
      },
      "source": [
        "sys_agent.response(\"Book a table for 5 , this Sunday .\")"
      ],
      "execution_count": 9,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "'Here is the booking information : booking was successful . reference number is : 00000003.'"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 9
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "hnxPfsenzLsw",
        "colab_type": "text"
      },
      "source": [
        "## Build a Simulator to Chat with the Agent and Evaluate\n",
        "\n",
        "In many one-to-one task-oriented dialog system, a simulator is essential to train an RL agent. In our framework, we doesn't distinguish user or system, all speakers are **agents**. The simulator is also an agent, with specific policy inside for accomplishing the user goal.\n",
        "\n",
        "We use Agenda policy for the simulator, this policy requires dialog act input, which means we should set DST argument of `PipelineAgent` to `None`. Then the `PipelineAgent` will pass dialog act to policy directly. Refer to `PipelineAgent` doc for more details."
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "CM2p1xwWzLsx",
        "colab_type": "code",
        "outputId": "dd00aec0-ec4f-4d1d-a805-49dca1a67abe",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 255
        }
      },
      "source": [
        "# bert nlu trained on sys sentence of multiwoz\n",
        "# go to README.md under `tatk/tatk/nlu/bert/multiwoz` for more information \n",
        "user_nlu = BERTNLU(mode='sys')\n",
        "# not use dst\n",
        "user_dst = None\n",
        "# rule policy\n",
        "user_policy = Rule(character='usr')\n",
        "# template NLG\n",
        "user_nlg = TemplateNLG(is_user=True)\n",
        "# assemble\n",
        "user_agent = PipelineAgent(user_nlu, user_dst, user_policy, user_nlg)"
      ],
      "execution_count": 10,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "load train, size 8434\n",
            "load val, size 999\n",
            "load test, size 1000\n",
            "loaded train, size 56750\n",
            "loaded val, size 7365\n",
            "loaded test, size 7372\n",
            "dialog act num: 34\n",
            "sentence label num: 64\n",
            "tag num: 312\n",
            "Load from model_file param\n",
            "Load from /content/tatk/tatk/nlu/bert/multiwoz/output/sys/bestcheckpoint.tar\n",
            "train step 29900\n",
            "BERTNLU loaded\n",
            "Loading goal model is done\n"
          ],
          "name": "stdout"
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "PgDsgQRCzLsz",
        "colab_type": "text"
      },
      "source": [
        "Now we have a simulator and an agent. we will use an existed simple one-to-one conversation controller `BiSession`, you can also define your own Session class for your special need. \n",
        "\n",
        "We add `MultiWozEvaluator` to evaluate the performance. It uses the parsed dialog act input and policy output dialog act to calculate **inform f1**, **book rate**, and whether the task is **success**."
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "xIHaiwndzLsz",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "evaluator = MultiWozEvaluator()\n",
        "sess = BiSession(sys_agent=sys_agent, user_agent=user_agent, kb_query=None, evaluator=evaluator)"
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "N3tkmnhXzLs1",
        "colab_type": "text"
      },
      "source": [
        "Let's make this two agents chat! The key is `next_turn` method of Session class."
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "kMiGhBFaU1Qk",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 1000
        },
        "outputId": "2d2d6950-31d9-403c-809c-49acc07bb900"
      },
      "source": [
        "random.seed(20190827)\n",
        "np.random.seed(20190827)\n",
        "sys_response = ''\n",
        "sess.init_session()\n",
        "print('init goal:')\n",
        "pprint(sess.evaluator.goal)\n",
        "print('-'*50)\n",
        "for i in range(40):\n",
        "    sys_response, user_response, session_over, reward = sess.next_turn(sys_response)\n",
        "    print('user:', user_response)\n",
        "    print('sys:', sys_response)\n",
        "    print()\n",
        "    if session_over is True:\n",
        "        print('task success:', sess.evaluator.task_success())\n",
        "        print('book rate:', sess.evaluator.book_rate())\n",
        "        print('inform precision/recall/f1:', sess.evaluator.inform_F1())\n",
        "        print('-'*50)\n",
        "        print('final goal:')\n",
        "        pprint(sess.evaluator.goal)\n",
        "        print('='*100)\n",
        "        break"
      ],
      "execution_count": 12,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "init goal:\n",
            "{'attraction': {'info': {'area': 'centre', 'type': 'college'},\n",
            "                'reqt': {'entrance fee': '?', 'phone': '?'}},\n",
            " 'train': {'book': {'people': '7'},\n",
            "           'booked': '?',\n",
            "           'info': {'day': 'wednesday',\n",
            "                    'departure': 'cambridge',\n",
            "                    'destination': 'london kings cross',\n",
            "                    'leaveAt': '12:15'},\n",
            "           'reqt': {'duration': '?'}}}\n",
            "--------------------------------------------------\n",
            "user: Do you have any college attractions. I am also looking for places to go in town . maybe something in the centre .\n",
            "sys: There are 44 , anything in particular you are looking for ? I 'd recommend the fez club . would you like some information on it ?\n",
            "\n",
            "user: Can you give me their phone number please ? Yes , what are the entrance fees ?\n",
            "sys: Its entrance fee is ? . The phone number is 01223300085 .\n",
            "\n",
            "user: I just need to know how much the entrance fee is .\n",
            "sys: The park is ? .\n",
            "\n",
            "user: Okay , are there any colleges in the centre ?\n",
            "sys: There are 13 . would you like me to recommend one for you ? Would you like hughes hall ?\n",
            "\n",
            "user: I just need to know how much the entrance fee is .\n",
            "sys: Their entrance fee is free by our system currently .\n",
            "\n",
            "user: I am departing from cambridge . I will leav on wednesday . I would like to leave anytime after 12:15 . I need to find a train to london kings cross please .\n",
            "sys: When would you like to leave by ? Where did you want to depart from ?\n",
            "\n",
            "user: The earlier the better , so whichever train leaves closest to 12:15. I ' m looking to travel on wednesday. Is it going to cambridge ?\n",
            "sys: Where will you be leaving from ?\n",
            "\n",
            "user: Thanks ! i also need a train departing from cambridge .\n",
            "sys: Where are you departing from ?\n",
            "\n",
            "user: I need some information on a train going to london kings cross . I ' m departing from cambridge .\n",
            "sys: Where will you be leaving from ?\n",
            "\n",
            "user: I 'll be departing from cambridge .\n",
            "sys: Where will you be traveling from ?\n",
            "\n",
            "user: I ' m departing from cambridge .\n",
            "sys: Where are you departing from ?\n",
            "\n",
            "user: I am going to london kings cross. I ' m departing from cambridge .\n",
            "sys: Where did you want to depart from ?\n",
            "\n",
            "user: I ' m also looking for a train from cambridge .\n",
            "sys: Would you like me to book you on the 12:15 train ? I can book your tickets for wednesday . Woudl you like me to book a train to cambridge for you ? Woudl you like me to book a train from cambridge for you ?\n",
            "\n",
            "user: Yes , what is the duration of the train ride ?\n",
            "sys: The trip will last 51 minutes.\n",
            "\n",
            "user: Yes , can you book that for 7 ?\n",
            "sys: All set . your reference number is 00000024 .\n",
            "\n",
            "user: You were great . goodbye .\n",
            "sys: We have 110 such places . The pipasha restaurant is a nice place would you like to try that one ?\n",
            "\n",
            "task success: 1\n",
            "book rate: 1.0\n",
            "inform precision/recall/f1: (1.0, 1.0, 1.0)\n",
            "--------------------------------------------------\n",
            "final goal:\n",
            "{'attraction': {'info': {'area': 'centre', 'type': 'college'},\n",
            "                'reqt': {'entrance fee': 'free', 'phone': '01223300085'}},\n",
            " 'train': {'book': {'people': '7'},\n",
            "           'booked': 'yes',\n",
            "           'info': {'day': 'wednesday',\n",
            "                    'departure': 'cambridge',\n",
            "                    'destination': 'london kings cross',\n",
            "                    'leaveAt': '12:15'},\n",
            "           'reqt': {'duration': '51 minutes'}}}\n",
            "====================================================================================================\n"
          ],
          "name": "stdout"
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "bP75e8TRMznh",
        "colab_type": "text"
      },
      "source": [
        "`BiSession` allows two agents chat in dialog act level or natural language level, once the input and output are consistent. Example configurations:\n",
        "\n",
        "| usr input ==>       | usr NLU | usr DST | usr Policy | usr NLG  | ==> sys input ==>        | sys NLU | sys DST | sys Policy | sys NLG  |\n",
        "| ---------------- | ------- | ------- | ---------- | -------- | ---------------- | ------- | ------- | ---------- | -------- |\n",
        "| Dialog act       | None    | Rule    | Rule       | None     | Dialog act       | None    | None    | Rule       | None     |\n",
        "| Natural language | Bert    | Rule    | Rule       | None     | Dialog act       | None    | None    | Rule       | Template |\n",
        "| Dialog act       | None    | Rule    | Rule       | Template | Natural language | SVM     | None    | Rule       | None     |\n",
        "| Natural language | Bert    | Rule    | Rule       | Template | Natural language | SVM     | None    | Rule       | Template |\n",
        "\n",
        "\n",
        "We have tried the last configuration before. Let's try the second configuration.\n"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "xdhFIGIJQNNF",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "user_agent = PipelineAgent(user_nlu, user_dst, user_policy, None)\n",
        "sys_agent = PipelineAgent(None, sys_dst, sys_policy, sys_nlg)\n",
        "evaluator = MultiWozEvaluator()\n",
        "sess = BiSession(sys_agent=sys_agent, user_agent=user_agent, kb_query=None, evaluator=evaluator)"
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "izje_L5UaTMb",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 836
        },
        "outputId": "f2a22ff6-b075-47f8-c5b1-d54e20639b85"
      },
      "source": [
        "random.seed(20190827)\n",
        "np.random.seed(20190827)\n",
        "sys_response = ''\n",
        "sess.init_session()\n",
        "print('init goal:')\n",
        "pprint(sess.evaluator.goal)\n",
        "print('-'*50)\n",
        "for i in range(40):\n",
        "    sys_response, user_response, session_over, reward = sess.next_turn(sys_response)\n",
        "    print('user:', user_response)\n",
        "    print('sys:', sys_response)\n",
        "    print()\n",
        "    if session_over is True:\n",
        "        print('task success:', sess.evaluator.task_success())\n",
        "        print('book rate:', sess.evaluator.book_rate())\n",
        "        print('inform precision/recall/f1:', sess.evaluator.inform_F1())\n",
        "        print('-'*50)\n",
        "        print('final goal:')\n",
        "        pprint(sess.evaluator.goal)\n",
        "        print('='*100)\n",
        "        break"
      ],
      "execution_count": 14,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "init goal:\n",
            "{'attraction': {'info': {'area': 'centre', 'type': 'college'},\n",
            "                'reqt': {'entrance fee': '?', 'phone': '?'}},\n",
            " 'train': {'book': {'people': '7'},\n",
            "           'booked': '?',\n",
            "           'info': {'day': 'wednesday',\n",
            "                    'departure': 'cambridge',\n",
            "                    'destination': 'london kings cross',\n",
            "                    'leaveAt': '12:15'},\n",
            "           'reqt': {'duration': '?'}}}\n",
            "--------------------------------------------------\n",
            "user: {'Attraction-Inform': [['Type', 'college'], ['Area', 'centre']]}\n",
            "sys: There are 13 , anything in particular you are looking for ? I 'd recommend emmanuel college . would you like some information on it ?\n",
            "\n",
            "user: {'Attraction-Request': [['Phone', '?'], ['Fee', '?']]}\n",
            "sys: The phone number is 01223334900 . Their entrance fee is free by our system currently .\n",
            "\n",
            "user: {'Train-Inform': [['Depart', 'cambridge'], ['Day', 'wednesday'], ['Leave', '12:15'], ['Dest', 'london kings cross']]}\n",
            "sys: Would you like me to book you on the 12:15 train ? Would you like to take the train on wednesday ? Woudl you like me to book a train to london kings cross for you ? Woudl you like me to book a train from cambridge for you ?\n",
            "\n",
            "user: {'Train-Inform': [['Dest', 'london kings cross']]}\n",
            "sys: There is a train arriving at 12:15 would you like me to book tickets for that one ? I can book your tickets for wednesday . Woudl you like me to book a train to london kings cross for you ? Woudl you like me to book a train from cambridge for you ?\n",
            "\n",
            "user: {'Train-Request': [['Time', '?']]}\n",
            "sys: That would be 51 minutes .\n",
            "\n",
            "user: {'Train-Inform': [['People', '7']]}\n",
            "sys: Booking was successful . reference number is : 00000024 .\n",
            "\n",
            "user: {'general-bye': [['none', 'none']]}\n",
            "sys: Thank you for using our services .\n",
            "\n",
            "task success: 1\n",
            "book rate: 1.0\n",
            "inform precision/recall/f1: (1.0, 1.0, 1.0)\n",
            "--------------------------------------------------\n",
            "final goal:\n",
            "{'attraction': {'info': {'area': 'centre', 'type': 'college'},\n",
            "                'reqt': {'entrance fee': 'free', 'phone': '01223334900'}},\n",
            " 'train': {'book': {'people': '7'},\n",
            "           'booked': 'yes',\n",
            "           'info': {'day': 'wednesday',\n",
            "                    'departure': 'cambridge',\n",
            "                    'destination': 'london kings cross',\n",
            "                    'leaveAt': '12:15'},\n",
            "           'reqt': {'duration': '51 minutes'}}}\n",
            "====================================================================================================\n"
          ],
          "name": "stdout"
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "E3WOc0rZaZaL",
        "colab_type": "text"
      },
      "source": [
        "After removing user NLG and system NLU, the conversation is more efficient."
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "collapsed": true,
        "id": "G0_s-zNCzLs5",
        "colab_type": "text"
      },
      "source": [
        "## Try Different Module Combinations\n",
        "\n",
        "The combination modes of pipeline agent modules are flexible. We support joint model such as [MDBT](https://www.aclweb.org/anthology/P18-2069) (NLU+DST) and [MDRG](https://pdfs.semanticscholar.org/47d0/1eb59cd37d16201fcae964bd1d2b49cfb55e.pdf) (Policy+NLG), once the input and output are matched with previous and next module. We also support End2End model such as [Sequicity](https://www.comp.nus.edu.sg/~kanmy/papers/acl18-sequicity.pdf)."
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "ge5RMjEEzLs6",
        "colab_type": "text"
      },
      "source": [
        "### MDBT\n",
        "- NLU: None\n",
        "- DST: MDBT\n",
        "- Policy: Rule\n",
        "- NLG: TemplateNLG"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "jX389QdrzLs6",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "from tatk.dst.mdbt.multiwoz.mdbt import MultiWozMDBT\n",
        "nlu = None\n",
        "# simple rule DST\n",
        "dst = MultiWozMDBT()\n",
        "# rule policy\n",
        "policy = Rule()\n",
        "# template NLG\n",
        "nlg = TemplateNLG(is_user=False)\n",
        "# assemble\n",
        "sys_agent = PipelineAgent(nlu, dst, policy, nlg)"
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "ywmBimGmzLs8",
        "colab_type": "text"
      },
      "source": [
        "### MDRG\n",
        "\n",
        "- NLU: SVM\n",
        "- DST: Rule\n",
        "- Policy: MDRG\n",
        "- NLG: None"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "8f1JhaELzLs8",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "from tatk.policy.mdrg.multiwoz.policy import MDRGWordPolicy\n",
        "# svm nlu trained on usr sentence of multiwoz\n",
        "# go to README.md under `tatk/tatk/nlu/svm/multiwoz` for more information \n",
        "nlu = SVMNLU(mode='usr')\n",
        "# simple rule DST\n",
        "dst = RuleDST()\n",
        "# rule policy\n",
        "policy = MDRGWordPolicy()\n",
        "# template NLG\n",
        "nlg = None\n",
        "# assemble\n",
        "sys_agent = PipelineAgent(nlu, dst, policy, nlg)"
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "collapsed": true,
        "id": "Ndki-MWnzLs9",
        "colab_type": "text"
      },
      "source": [
        "### Sequicity\n",
        "\n",
        "Sequicity inherits from interface `Agent` directly."
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "yEs1yzMYzLs-",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "from tatk.e2e.sequicity.multiwoz import Sequicity\n",
        "sequicity = Sequicity()\n",
        "sys_agent = sequicity"
      ],
      "execution_count": 0,
      "outputs": []
    }
  ]
}